// vue-router 导出
import Router from 'vue-router';
import { store } from '@/store';
import Login from '@component/Login.vue';
import Main from '@component/Main.vue';

/** 平台管理 */
// 会员审核
import MemberCheck from '@component/manage/member/Check.vue';
// 票据审核
import BillCheck from '@component/manage/BillCheck.vue';
// 订单管理
import OrderCheck from '@component/manage/OrderCheck.vue';
// 匹配报价
import MatchingQuote from '@component/manage/MatchingQuote.vue';
import MatchResult from '@component/manage/MatchResult.vue';

/** 系统管理 */
import MenuManage from '@component/system/MenuManage.vue';
import RoleManage from '@component/system/role/RoleManage.vue';
import CustomerManage from '@component/system/CustomerManage.vue';
import HolidayManage from '@component/system/HolidayManage.vue';
import LeaveManage from '@component/system/LeaveManage.vue';
import AddressManage from '@component/system/AddressManage.vue';
import BankManage from '@component/system/BankManage.vue';
import ReportLoseManage from '@component/system/ReportLoseManage.vue';

/** 账户管理 */
// 汇票豆管理
import DraftBeans from '@component/account/draftbeans/Index.vue';
import DraftBeansDetail from '@component/account/draftbeans/Detail.vue';
import VisitLog from '@component/account/draftbeans/VisitLog.vue';
// 收益提现
import Withdrawal from '@component/account/Withdrawal.vue';
// 提现记录
import WithdrawalRecord from '@component/account/WithdrawalRecord.vue';
// 兴业账户管理
import CIB from '@component/account/CIB.vue';
import EvaluateManage from '@component/account/EvaluateManage.vue';
import SendXYManage from '@component/account/SendXYManage.vue';

/** 交易管理 */
// 客户预约出票
import Reservation from '@component/trade/Reservation.vue';
// 成交额管理
import Turnover from '@component/trade/Turnover.vue';
import WantBill from '@component/trade/wantBill/Index.vue';
import NewOffer from '@component/trade/wantBill/NewOffer.vue';
import NewWantBill from '@component/trade/wantBill/NewWantBill.vue';

/** 统计查询 */
// 会员查询
import MemberQuery from '@component/analyze/MemberQuery.vue';
import BillQuery from '@component/analyze/BillQuery.vue';
import OrderQuery from '@component/analyze/OrderQuery.vue';

/** 新闻公告 */
import BannerImg from '@component/news/BannerImg.vue';
import WebsiteNotice from '@component/news/WebsiteNotice.vue';

/** 上传管理 */
import ImageUploadManage from '@component/upload/ImageUploadManage.vue';

const routes = [
    { path: '/', component: Login },
    { path: '/login', component: Login },
    {
        path: '/platform',
        component: Main,
        meta: {
            breadCrumb: '交易管理'
        },
        children: [{
            path: 'membercheck',
            component: MemberCheck,
            meta: {
                breadCrumb: '会员审核'
            }
        }, {
            path: 'billcheck',
            component: BillCheck,
            meta: {
                breadCrumb: '票据审核'
            }
        }, {
            path: 'ordercheck',
            component: OrderCheck,
            meta: {
                breadCrumb: '订单管理'
            }
        }, {
            path: 'matchingquote',
            component: MatchingQuote,
            meta: {
                breadCrumb: '匹配报价'
            }
        },{
            path: 'matchresult/:bill_sum_price/:dead_date/:bill_flaws/:accept_type_id',
            component: MatchResult,
            meta: {
                breadCrumb: '匹配结果'
            }
        }
        ]
    }, {
        path: '/account',
        component: Main,
        meta: {
            breadCrumb: '账户管理'
        },
        children: [{
            path: 'draftbeans',
            component: DraftBeans,
            meta: {
                breadCrumb: '汇票豆管理'
            }
        }, {
            path: 'draftbeans/detail/:enterpriseId',
            component: DraftBeansDetail,
            props: true,
            meta: {
                breadCrumb: '收支明细'
            }
        }, {
            path: 'draftbeans/visitlog/:enterpriseId',
            component: VisitLog,
            props: true,
            meta: {
                breadCrumb: '访客操作记录'
            }
        }, {
            path: 'withdrawal',
            component: Withdrawal,
            meta: {
                breadCrumb: '收益提现'
            }
        },{
            path: 'withdrawalRecord',
            component: WithdrawalRecord,
            meta: {
                breadCrumb: '提现记录'
            }
        }, {
            path: 'cib',
            component: CIB,
            meta: {
                breadCrumb: '兴业账户管理'
            }
        }, {
            path: 'evaluate',
            component: EvaluateManage,
            meta: {
                breadCrumb: '评价管理'
            }
        }, {
            path: 'sendXingYe',
            component: SendXYManage,
            meta: {
                breadCrumb: '发送兴业文件'
            }
        }]
    }, {
        path: '/trade',
        component: Main,
        meta: {
            breadCrumb: '交易管理'
        },
        children: [{
            path: 'reservation',
            component: Reservation,
            meta: {
                breadCrumb: '客户预约出票'
            }
        }, {
            path: 'turnover',
            component: Turnover,
            meta: {
                breadCrumb: '成交额管理'
            }
        }, {
            path: 'wantBill',
            component: WantBill,
            meta: {
                breadCrumb: '求购录入'
            }
        }, {
            path: 'newOffer/:id?',
            component: NewOffer,
            meta: {
                breadCrumb: '新建行口报价'
            }
        }, {
            path: 'newWantBill',
            component: NewWantBill,
            meta: {
                breadCrumb: '新建货款报价'
            }
        }]
    }, {
        path: '/sys',
        component: Main,
        meta: {
            breadCrumb: '系统管理'
        },
        children: [{
            path: 'menu',
            component: MenuManage,
            meta: {
                breadCrumb: '菜单管理'
            },
        },{
            path: 'role',
            component: RoleManage,
            meta: {
                breadCrumb: '角色管理'
            }
        },{
            path: 'customer',
            component: CustomerManage,
            meta: {
                breadCrumb: '用户管理'
            }
        },{
            path: 'holiday',
            component: HolidayManage,
            meta: {
                breadCrumb: '假日管理'
            }
        }, {
            path: 'leave',
            component: LeaveManage,
            meta: {
                breadCrumb: '会员等级管理'
            }
        }, {
            path: 'address',
            component: AddressManage,
            meta: {
                breadCrumb: '地址管理'
            }
        }, {
            path: 'bank',
            component: BankManage,
            meta: {
                breadCrumb: '银行管理'
            }
        }, {
            path: 'reportLose',
            component: ReportLoseManage,
            meta: {
                breadCrumb: '挂失管理'
            }
        }]
    }, {
        path: '/statisticsFind',
        component: Main,
        meta: {
            breadCrumb: '统计/查询'
        },
        children: [{
            path: 'menberFind',
            component: MemberQuery,
            meta: {
                breadCrumb: '会员查询'
            }
        }, {
            path: 'billStatistics',
            component: BillQuery,
            meta: {
                breadCrumb: '票据统计'
            }
        }, {
            path: 'orderStatistics',
            component: OrderQuery,
            meta: {
                breadCrumb: '订单统计'
            }
        }]
    }, {
        path: '/newNotice',
        component: Main,
        meta: {
            breadCrumb: '新闻公告'
        },
        children: [{
            path: 'bannerImg',
            component: BannerImg,
            meta: {
                breadCrumb: '首页大图'
            }
        }, {
            path: 'websiteNotice',
            component: WebsiteNotice,
            meta: {
                breadCrumb: '网站公告'
            }
        }]
    }, {
        path: '/adminUpload',
        component: Main,
        meta: {
            breadCrumb: '上传管理'
        },
        children: [{
            path: 'upload',
            component: ImageUploadManage,
            meta: {
                breadCrumb: '上传图片'
            }
        }]
    }
];

const router = new Router({
    mode: 'hash',
    scrollBehavior(to, from, savedPosition) {
        return { x: 0, y: 0 }
    },
    routes
});

router.beforeEach((to, from, next) => {
    let token = localStorage.getItem('Authorization');
    if (!token && to.path !== '/login') {
        router.push('/login');
        return false;
    }
    next();
    // store.commit('setBreadCrumb', to.matched.map(e => e.meta.breadCrumb)); 
    store.commit('setBreadCrumb', [to.matched[0].meta.breadCrumb, to.meta.breadCrumb])
})

export default router;